package com.d0327;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class WordCount {
    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader(new File("src/com/d0327/a.txt"));
        BufferedReader br = new BufferedReader(fr);
        Map<String,Integer>map=new HashMap<>();
        String str=null;
        StringBuilder sb=new StringBuilder();//读取文件
        while((str=br.readLine())!=null) {
            sb.append(str);//拼接
        }
            String countext = sb.toString();
            String[] words = countext.split("[ \n,.]");
            for (String word :
                    words) {
                if (word.equals("")) {
                    continue;
                }
                if (map.get(word) == null) {//第一次存取
                    map.put(word, 1);
                } else {//第一次存取
                    int oldValue = map.get(word);
                    map.put(word, oldValue + 1);
                }
            }
        map.forEach((K, V) -> System.out.println(K + "\t" + V)); }
}


